/**
 * Created by Fly on 2016/9/23.
 */
var DBPool=require('../util/DBpool');
module.exports= {
    getinfo:function (req,res,callback){
        var usertel=req.session.usertel;
        var sql="SELECT *FROM `order` WHERE userno=? ORDER BY dealdate DESC";
        DBPool.getConnection(function (client) {
            client.query('SELECT userno FROM t_userinfo WHERE tel=?',[usertel],function (error,result) {
                if(error){
                    console.log(error.message);
                    return;
                }
                var userno=result[0].userno;
                client.query(sql,[userno],function (error,result) {
                    if(error){
                        console.log(error.message);
                        return;
                    }
                    callback(result);
                    client.release();
                });
            });
        });
    },
    del:function (req,callback){
        var needsno=req.body.needsno;
        var orderno=req.body.orderno;
        var sql_needs="DELETE FROM t_needs WHERE needsno=?";
        var sql_order="DELETE FROM t_order WHERE orderno=?";
        DBPool.getConnection(function (client) {
            client.query(sql_order,[orderno],function (error,result) {
                if(error){
                    console.log(error.message);
                    return;
                }
                DBPool.getConnection(function (client) {
                    client.query(sql_needs,[needsno],function (error,result) {
                        if(error){
                            console.log(error.message);
                            return;
                        }
                        callback(result);
                        client.release();
                    });
                });
            });
        });
    }
};
